/// information on hours of volunteering just for years 2001, 2003, and 2005. For 2017 to be included, hopefully comparable with previous years
/// "yes/no" answer for year 2011 for the extensive margin. Jimmy

// Author: Laura Montenovo
// In this do file, for each year of the volunteering data, I make sure missing values actually have a dot "."
// for the following variables: extensive margin, hours volunteered, hispanic, education level
// we save the output as IUPUI_year

// this is a process of preliminary cleaning of IUPUI data before it gets merged to taxsim input (PSID) and output

cd "W:\Lab\Lab-heimb\Montenovo\Data\IUPUI Volunteer Data"
use fam-2001-cr298A_v04a-Merge-Extract.dta, clear

capture log close
log using IUPUI_year, replace

**EXTENSIVE MARGIN volunteer
replace Hyear=. if Hyear>1
sum Hyear
/*
   Variable |        Obs        Mean    Std. Dev.       Min        Max
-------------+---------------------------------------------------------
       Hyear |      7,272    .3169692     .939834          0          9
*/

replace Wyear=. if Wyear>1
sum Wyear
/*

    Variable |        Obs        Mean    Std. Dev.       Min        Max
-------------+---------------------------------------------------------
       Wyear |      4,182    .3988522    1.043736          0          9

*/


** INTENSIVE MARGIN volunteer
** hoursHLB: hours volunteered by husband

sum hoursHLB if hoursHacc==0 // for the most accurate estimates only
replace hoursHLB=. if hoursHacc!=0
sum hoursHLB
/*
    Variable |        Obs        Mean    Std. Dev.       Min        Max
-------------+---------------------------------------------------------
    hoursHLB |      7,160    29.66704    129.6067          0       3744
*/

** hoursWLB: hours volunteered by wife
sum hoursWLB if hoursWacc==0 // for the most accurate estimates only
replace hoursWLB=. if hoursHacc!=0
/*
    Variable |        Obs        Mean    Std. Dev.       Min        Max
-------------+---------------------------------------------------------
    hoursWLB |      4,110    35.83625    127.9943          0       2500
*/

gen total_giving=Arelig + Asecular10
tab total_giving

/*
    Variable |        Obs        Mean    Std. Dev.       Min        Max
-------------+---------------------------------------------------------
total_g~2001 |      7,406    1140.926    6411.279          0     491500
*/

replace hispanH2001=. if hispanH2001>1
rename hispanH2001 hispanic_head
replace hispanW2001=. if hispanW2001>1
rename hispanW2001 hispanic_wife

replace ceduch2001=. if ceduch2001>20
rename ceduch2001 education_head
replace ceducw2001=. if ceducw2001>20
rename ceducw2001 education_wife


rename ageH2001 ageH
rename ageW2001 ageS

keep family_id Hyear Wyear hoursHLB hoursWLB hoursWacc total_giving hispanic_head hispanic_wife education_head education_wife

order family_id Hyear Wyear hoursHLB hoursWLB hoursWacc total_giving hispanic_head hispanic_wife education_head education_wife
save IUPUI_2001.dta, replace

/////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////

use cr299_2003_EXTRACT_v006.dta, clear

**EXTENSIVE MARGIN volunteer
sum Hyear if Hyear<701
replace Hyear=. if Hyear>1


/*
    Variable |        Obs        Mean    Std. Dev.       Min        Max
-------------+---------------------------------------------------------
       Hyear |      7,596    .2755398    .5348051          0          9
*/

sum Wyear if Wyear<701
replace Wyear=. if Wyear>1
sum Hyear Wyear


/*
    Variable |        Obs        Mean    Std. Dev.       Min        Max
-------------+---------------------------------------------------------
       Wyear |      4,180    .3217703    .5688363          0          9
*/

** INTENSIVE MARGIN volunteer
** hoursHLB: hours volunteered by husband

replace ArelgHLB=. if ArelgHLB<0
replace AsecularHLB=. if AsecularHLB<0

replace ArelgHLB=. if ArelgHLB>8760
replace AsecularHLB=. if AsecularHLB>8760

replace ArelgWLB=. if ArelgWLB>8760
replace AsecularWLB=. if AsecularWLB>8760

gen hoursHLB=ArelgHLB+AsecularHLB if ArelgHLB!=-999 & AsecularHLB!=-999
sum hoursHLB 

/*
    Variable |        Obs        Mean    Std. Dev.       Min        Max
-------------+---------------------------------------------------------
    hoursHLB |      7,620    55.90197    493.6205          0      37094
*/

** hoursWLB: hours volunteered by wife
replace ArelgWLB=. if ArelgWLB<0
replace AsecularWLB=. if AsecularWLB<0

sum ArelgWLB AsecularWLB

gen hoursWLB=ArelgWLB+AsecularWLB 
sum hoursWLB

/*
    Variable |        Obs        Mean    Std. Dev.       Min        Max
-------------+---------------------------------------------------------
    hoursWLB |      4,295    54.68277    167.8367          0       2636
*/

gen total_giving=Arelig + Asecular10
tab total_giving
sum total_giving

/*
    Variable |        Obs        Mean    Std. Dev.       Min        Max
-------------+---------------------------------------------------------
total_g~2003 |      7,822    1102.195    2905.778          0     110000
*/

replace hispanH2003=. if hispanH2003>1
rename hispanH2003 hispanic_head

replace hispanW2003=. if hispanW2003>1
rename hispanW2003 hispanic_wife

replace ceduch2003=. if ceduch2003>20
rename ceduch2003 education_head

replace ceducw2003=. if ceducw2003>20
rename ceducw2003 education_wife


rename ageH2003 ageH
rename ageW2003 ageS

keep family_id Hyear Wyear hoursHLB hoursWLB total_giving hispanic_head hispanic_wife education_head education_wife Arelig Ayouth Aenvir Acomb Aneed Ahlth Aeduc Aart Aneig Aintl Aoth Asecular10 ArelgHLB ArelgWLB AyothHLB AyothWLB AsenrHLB AsenrWLB AhlthHLB AhlthWLB AneedHLB AneedWLB AsoclHLB AsoclWLB AothrHLB AothrWLB AsecularHLB AsecularWLB

order family_id Hyear Wyear hoursHLB hoursWLB total_giving hispanic_head hispanic_wife education_head education_wife Arelig Ayouth Aenvir Acomb Aneed Ahlth Aeduc Aart Aneig Aintl Aoth Asecular10 ArelgHLB ArelgWLB AyothHLB AyothWLB AsenrHLB AsenrWLB AhlthHLB AhlthWLB AneedHLB AneedWLB AsoclHLB AsoclWLB AothrHLB AothrWLB AsecularHLB AsecularWLB

save IUPUI_2003.dta, replace

/////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////

use cr299_2005_EXTRACT_v004.dta, clear

**EXTENSIVE MARGIN volunteer
sum Hyear if Hyear<701
replace Hyear=. if Hyear>1
sum Hyear

/*
    Variable |        Obs        Mean    Std. Dev.       Min        Max
-------------+---------------------------------------------------------
       Hyear |      7,753    .2929189    .5815557          0          9
*/

sum Wyear if Wyear<701
replace Wyear=. if Wyear>1
sum Wyear

/*
    Variable |        Obs        Mean    Std. Dev.       Min        Max
-------------+---------------------------------------------------------
       Wyear |      4,342    .3546753    .5920848          0          9
*/


** INTENSIVE MARGIN volunteer
** hoursHLB: hours volunteered by husband
replace ArelgHLB=. if ArelgHLB<0
replace AsecularHLB=. if AsecularHLB<0
tab ArelgHLB
replace ArelgHLB=. if ArelgHLB>8760
replace AsecularHLB=. if AsecularHLB>8760

sum ArelgHLB AsecularHLB

gen hoursHLB=ArelgHLB+AsecularHLB 
sum hoursHLB
/*
    Variable |        Obs        Mean    Std. Dev.       Min        Max
-------------+---------------------------------------------------------
    hoursHLB |      7,785    56.92036    432.3966          0      31200
*/

** hoursWLB: hours volunteered by wife
replace ArelgHLB=. if ArelgWLB<0
replace AsecularWLB=. if AsecularWLB<0
replace ArelgWLB=. if ArelgWLB>8760
replace AsecularWLB=. if AsecularWLB>8760

gen hoursWLB=ArelgWLB+AsecularWLB 
sum hoursWLB

/*
    Variable |        Obs        Mean    Std. Dev.       Min        Max
-------------+---------------------------------------------------------
    hoursWLB |      4,423    57.10106    236.9601          0      11723
*/


gen total_giving=Arelig + Asecular10
tab total_giving
sum total_giving

/*
    Variable |        Obs        Mean    Std. Dev.       Min        Max
-------------+---------------------------------------------------------
total_g~2005 |      8,002    1225.854    3353.608          0     100000

*/

replace hispanH2005=. if hispanH2005>1
rename hispanH2005 hispanic_head

replace hispanW2005=. if hispanW2005>1
rename hispanW2005 hispanic_wife

replace ceduch2005=. if ceduch2005>20
rename ceduch2005 education_head

replace ceducw2005=. if ceducw2005>20
rename ceducw2005 education_wife

rename ageH2005 ageH
rename ageW2005 ageS

keep family_id Hyear Wyear hoursHLB hoursWLB total_giving hispanic_head hispanic_wife education_head education_wife Arelig Ayouth Aenvir Acomb Aneed Ahlth Aeduc Aart Aneig Aintl Aoth Asecular10 ArelgHLB ArelgWLB AyothHLB AyothWLB AsenrHLB AsenrWLB AhlthHLB AhlthWLB AneedHLB AneedWLB AsoclHLB AsoclWLB AothrHLB AothrWLB AsecularHLB AsecularWLB

order family_id Hyear Wyear hoursHLB hoursWLB total_giving hispanic_head hispanic_wife education_head education_wife Arelig Ayouth Aenvir Acomb Aneed Ahlth Aeduc Aart Aneig Aintl Aoth Asecular10 ArelgHLB ArelgWLB AyothHLB AyothWLB AsenrHLB AsenrWLB AhlthHLB AhlthWLB AneedHLB AneedWLB AsoclHLB AsoclWLB AothrHLB AothrWLB AsecularHLB AsecularWLB

save IUPUI_2005.dta, replace

/////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////
/*
use fam-2007-cr298A_v05a-Merge-Extract.dta, clear

** NO VOLUNTEER DATA

rename fid2007 family_id

gen total_giving=Arelig + Asecular10
tab total_giving
sum total_giving

/*
    Variable |        Obs        Mean    Std. Dev.       Min        Max
-------------+---------------------------------------------------------
total_g~2007 |      8,289    1261.473    3320.289          0      91600
*/

rename hispanH2007 hispanic_head
rename hispanW2007 hispanic_wife

rename ceduch2007 education_head
rename ceducw2007 education_wife

keep family_id total_giving hispanic_head hispanic_wife education_head education_wife

order family_id Hyear Wyear hoursHLB hoursWLB total_giving hispanic_head hispanic_wife education_head education_wife

save IUPUI_2007.dta, replace

/////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////

use fam-2009-cr298A_v03a-Merge-Extract.dta, clear

** NO VOLUNTEER DATA

gen total_giving_2009=Arelig + Asecular10
tab total_giving_2009
sum total_giving_2009

/*
    Variable |        Obs        Mean    Std. Dev.       Min        Max
-------------+---------------------------------------------------------
total_g~2009 |      8,690    1250.798    3388.008          0      91025

*/
*/

/////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////

use fam-2011-cr298A_v03a-Merge-Extract.dta, clear

gen total_giving=Arelig + Asecular10
tab total_giving
sum total_giving

/*    Variable |        Obs        Mean    Std. Dev.       Min        Max
-------------+---------------------------------------------------------
total_g~2011 |      8,907    1191.038    3495.862          0     113500
*/
replace hispanH2011=. if hispanH2011>1
rename hispanH2011 hispanic_head

replace hispanW2011=. if hispanW2011>1
rename hispanW2011 hispanic_wife

replace ceduch2011=. if ceduch2011>20
rename ceduch2011 education_head

replace ceducw2011=. if ceducw2011>20
rename ceducw2011 education_wife

merge 1:1 family_id using fam-2001-volunteerdata.dta

rename VltrH Hyear
rename VltrW Wyear

rename ageH2011 ageH
rename ageW2011 ageS

keep family_id Hyear Wyear total_giving hispanic_head hispanic_wife education_head education_wife Arelig Ayouth Aenvir Acomb Aneed Ahlth Aeduc Aart Aneig Aintl Aoth Asecular10 VltrH_relig VltrW_relig VltrH_youth VltrH_senior VltrH_health VltrH_poverty VltrH_change VltrH_other VltrW_youth VltrW_senior VltrW_health VltrW_poverty VltrW_change VltrW_other

order family_id Hyear Wyear total_giving hispanic_head hispanic_wife education_head education_wife Arelig Ayouth Aenvir Acomb Aneed Ahlth Aeduc Aart Aneig Aintl Aoth Asecular10 VltrH_relig VltrW_relig VltrH_youth VltrH_senior VltrH_health VltrH_poverty VltrH_change VltrH_other VltrW_youth VltrW_senior VltrW_health VltrW_poverty VltrW_change VltrW_other


save IUPUI_2011.dta, replace

/////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////

/*
use fam-2013-cr298A_v02b-Merge-Extract.dta, clear

gen total_giving_2013=Arelig + Asecular10
tab total_giving_2013
sum total_giving_2013

 Variable |        Obs        Mean    Std. Dev.       Min        Max
-------------+---------------------------------------------------------
total_g~2013 |      9,063    1145.721    3580.631          0     106847

*/

/////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////

use fam-2017-cr298A_v02b-Merge-Extract.dta, clear

gen total_giving=Arelig + Asecular10
tab total_giving
sum total_giving

/* 

   Variable |        Obs        Mean    Std. Dev.       Min        Max
-------------+---------------------------------------------------------
total_g~2017 |      9,607    1122.717    4780.464          0     274997

*/
**EXTENSIVE MARGIN volunteer
sum HVolunteer 
rename HVolunteer Hyear

/*
    Variable |        Obs        Mean    Std. Dev.       Min        Max
-------------+---------------------------------------------------------
  HVolunteer |      9,607     .235141     .424109          0          1

*/

sum WVolunteer
rename WVolunteer Wyear

/*
    Variable |        Obs        Mean    Std. Dev.       Min        Max
-------------+---------------------------------------------------------
  WVolunteer |      9,607    .1768502    .3815618          0          1

*/


** INTENSIVE MARGIN volunteer
** Hhour_volunteer: hours volunteered by husband in a week
sum Hhour_volunteer
gen hoursHLB=Hhour_volunteer*52.14
sum hoursHLB

/*

    Variable |        Obs        Mean    Std. Dev.       Min        Max
-------------+---------------------------------------------------------
Hhour_volu~r |      9,561    1.073737    3.541166          0         90

*/

** hoursWLB: hours volunteered by wife in a week
sum Whour_volunteer
gen hoursWLB=Whour_volunteer*52.14
sum hoursWLB
/*

    Variable |        Obs        Mean    Std. Dev.       Min        Max
-------------+---------------------------------------------------------
Whour_volu~r |      9,572    .8115336    3.150925          0        112

*/

replace hispanH2017=. if hispanH2017>1
rename hispanH2017 hispanic_head

replace hispanW2017=. if hispanW2017>1
rename hispanW2017 hispanic_wife

replace ceduch2017=. if ceduch2017>20
rename ceduch2017 education_head

replace ceducw2017=. if ceducw2017>20
rename ceducw2017 education_wife

rename ageH2017 ageH
rename ageW2017 ageS

keep family_id Hyear Wyear hoursHLB hoursWLB total_giving hispanic_head hispanic_wife education_head education_wife 
order family_id Hyear Wyear hoursHLB hoursWLB total_giving hispanic_head hispanic_wife education_head education_wife



save IUPUI_2017.dta, replace




/////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////

use fam-2019-cr298A_v01b-Merge-Extract.dta, clear

gen total_giving=Arelig + Asecular10
tab total_giving
sum total_giving

/* 

    Variable |        Obs        Mean    Std. Dev.       Min        Max
-------------+---------------------------------------------------------
total_giving |      9,569     1067.91    3788.296          0     136000


*/
**EXTENSIVE MARGIN volunteer
sum HVolunteer 
rename HVolunteer Hyear

/*
     Variable |        Obs        Mean    Std. Dev.       Min        Max
-------------+---------------------------------------------------------
  HVolunteer |      9,569    .2238478    .4168431          0          1

*/

sum WVolunteer
rename WVolunteer Wyear

/*
    Variable |        Obs        Mean    Std. Dev.       Min        Max
-------------+---------------------------------------------------------
  WVolunteer |      9,569    .1669976    .3729932          0          1

*/


** INTENSIVE MARGIN volunteer
** Hhour_volunteer: hours volunteered by husband in a week
sum Hhour_volunteer
gen hoursHLB=Hhour_volunteer*52.14
sum hoursHLB

/*

    Variable |        Obs        Mean    Std. Dev.       Min        Max
-------------+---------------------------------------------------------
Hhour_volu~r |      9,532    1.010596     3.50499          0        112

*/

** hoursWLB: hours volunteered by wife in a week
sum Whour_volunteer
gen hoursWLB=Whour_volunteer*52.14
sum hoursWLB
/*

    Variable |        Obs        Mean    Std. Dev.       Min        Max
-------------+---------------------------------------------------------
Whour_volu~r |      9,543    .7554228    2.858046          0         70

*/

replace hispanH2019=. if hispanH2019>1
rename hispanH2019 hispanic_head

replace hispanW2019=. if hispanW2019>1
rename hispanW2019 hispanic_wife

replace ceduch2019=. if ceduch2019>20
rename ceduch2019 education_head

replace ceducw2019=. if ceducw2019>20
rename ceducw2019 education_wife


rename ageH2019 ageH
rename ageW2019 ageS

rename fid2019 family_id

keep family_id Hyear Wyear hoursHLB hoursWLB total_giving hispanic_head hispanic_wife education_head education_wife

order family_id Hyear Wyear hoursHLB hoursWLB total_giving hispanic_head hispanic_wife education_head education_wife

save IUPUI_2019.dta, replace

log close